﻿-- =============================================
-- Author:		Sogeti
-- Create date: 07/10/07
-- Description:	This procedure updates /inserts a record into the UDDI_PendingCases table 
-- =============================================
CREATE PROCEDURE [dbo].[usp_update_pending_request]
	@Description varchar(255),
	@EndpointValue varchar(255),
	@Category varchar(50),
	@BindingType varchar(50),
	@TransportType varchar(50),
	@TransportLocation varchar(255),
	@UDDIContactName varchar(50),
	@UDDIUserType varchar(20),
	@UDDIEmail varchar(50),
	@BiztalkApplication varchar(255),
	@EndpointName varchar(255),
	@Status varchar(50),
	@ModifiedBy varchar(50),
	@ID uniqueidentifier,
	@TargetNamespace varchar(255),
	@MessageExchangePattern varchar(20),
	@JaxRPCResponse bit,
	@ServiceAction varchar(75),
	@CacheTimeOut int,
	@RequestAction varchar(50),
	@BusinessProvider varchar(255),
	@ServiceName varchar(255)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	if exists(Select * from EndPoints
			Where BizTalkApplication = @BiztalkApplication and
				EndpointName = @EndpointName)
	BEGIN

--if(select count(*) from EndPoints where ID=@ID) >0
--	BEGIN
	UPDATE [EndPoints]
	   SET [Description] = @Description,
		  [EndpointValue] = @EndpointValue,
		  [Category] = @Category,
		  [BindingType] = @BindingType,
		  [TransportType] = @TransportType,
		  [TransportLocation] = @TransportLocation,
		  [UDDIContactName] = @UDDIContactName, 
		  [UDDIEmail] = @UDDIEmail, 
		  [UDDIUserType] = @UDDIUserType,
		  [BiztalkApplication] = @BiztalkApplication,
		  [EndpointName] = @EndpointName,
		  [Status] = @Status,
	      [ModifiedBy] = @ModifiedBy,
		  [TargetNamespace] = @TargetNamespace,
		  [MessageExchangePattern] = @MessageExchangePattern,
		  [JaxRPCResponse] = @JaxRPCResponse,
		  [ServiceAction] = @ServiceAction,
		  [CacheTimeOut] = @CacheTimeOut,
		  [RequestAction] = @RequestAction,
		  [BusinessProvider] = @BusinessProvider,
		  [ServiceName] = @ServiceName
	 WHERE
		  BiztalkApplication = @BizTalkApplication and
		  EndpointName = @EndpointName
  
	END
  ELSE
	BEGIN 
		INSERT INTO [EndPoints]
           (ID
           ,[Description]
           ,[EndpointValue]
           ,[Category]
           ,[BindingType]
           ,[TransportType]
           ,[TransportLocation]
           ,[UDDIContactName]
           ,[UDDIEmail]
           ,[UDDIUserType]
           ,[BiztalkApplication]
           ,[EndpointName]
           ,[Status]
		   ,[ModifiedBy]
		   ,[TargetNamespace]
		   ,[MessageExchangePattern] 
		   ,[JaxRPCResponse]
		   ,[ServiceAction] 
		   ,[CacheTimeOut] 
		   ,[RequestAction]
		   ,[BusinessProvider]
		   ,[ServiceName]
)
     VALUES
           (@ID,
           @Description,
           @EndpointValue,
           @Category,
           @BindingType,
           @TransportType,
           @TransportLocation,
           @UDDIContactName, 
		   @UDDIEmail, 
           @UDDIUserType,
           @BiztalkApplication, 
		   @EndpointName, 
           @Status,
		   @ModifiedBy,
		   @TargetNamespace,
		   @MessageExchangePattern,
		   @JaxRPCResponse,
		   @ServiceAction,
		   @CacheTimeOut,
		   @RequestAction,
		   @BusinessProvider,
		   @ServiceName)
	END	

END
